package com.letoken.platform.repo.app.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.letoken.platform.repo.app.po.AppUserLamp;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 用户阿拉丁神灯信息表 Mapper 接口
 * </p>
 *
 * @author 作者
 * @since 2024-01-23
 */
public interface AppUserLampMapper extends BaseMapper<AppUserLamp> {

    @Select("select user_id userId,(team_performance+user_performance) teamPerformance from app_user_lamp p where user_id in (select user_id from app_user_team t where t.inviter_id = #{userId}) ORDER BY (team_performance+user_performance) desc limit 3")
    List<AppUserLamp> getLampList(@Param("userId") Integer userId);

    @Select("select sum(team_performance+user_performance) teamPerformance from app_user_lamp p where user_id in (select user_id from app_user_team t where t.inviter_id = #{userId}) and user_id != #{maxUserId}")
    BigDecimal sumTeamAmount(@Param("userId") Integer userId,@Param("maxUserId") Integer maxUserId);

    @Select("select * from app_user_lamp where `level`>0")
    List<AppUserLamp> getLampLevel();
}
